package com.yugao.fintech.antelope.pay.payment.channel;

import com.yugao.fintech.antelope.pay.constant.IfCodeEnum;
import com.yugao.fintech.framework.assistant.utils.exception.Assert;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public abstract class AbstractBillService implements IBillService {
    protected static String XLSX_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    protected static String XLS_CONTENT_TYPE = "application/vnd.ms-excel";
    protected static final Map<IfCodeEnum, IBillService> serviceMap = new ConcurrentHashMap<>();

    @PostConstruct
    public void abstractBillServiceInit() {
        IfCodeEnum ifCode = this.getIfCode();
        Assert.notNull(ifCode, "ifCode is null, class: " + this.getClass().getName());
        serviceMap.put(ifCode, this);
        log.info("load payOrderCloseService, class: {}", this.getClass().getSimpleName());
    }

    /**
     * 获取服务
     */
    public static IBillService getService(IfCodeEnum ifCodeEnum) {
        Assert.notNull(ifCodeEnum, "ifCode is null");
        // 获取支付接口服务
        return serviceMap.get(ifCodeEnum);
    }

    public static IBillService getService(String ifCode) {
        return getService(IfCodeEnum.ofByCode(ifCode));
    }

}
